package com.canaan.business.controller.pc.inOutStock;

import com.canaan.business.domain.inOutStock.YardageGoodsTaskOrder;
import com.canaan.business.domain.vo.YardageGoodsTaskOrderConfirmVo;
import com.canaan.business.service.inOutStock.IYardageGoodsTaskOrderService;
import com.canaan.common.annotation.Log;
import com.canaan.common.core.controller.BaseController;
import com.canaan.common.core.domain.AjaxResult;
import com.canaan.common.core.page.TableDataInfo;
import com.canaan.common.enums.BusinessType;
import com.canaan.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 码货任务单Controller
 *
 * @author ruoyi
 * @date 2023-01-30
 */
@Api(tags = "码货任务单")
@RestController
@RequestMapping("/inOutStock/yardageGoodsTaskOrder")
public class YardageGoodsTaskOrderController extends BaseController {
    @Autowired
    private IYardageGoodsTaskOrderService yardageGoodsTaskOrderService;

    /**
     * 查询码货任务单列表
     */
    @ApiOperation(value = "查询码货任务单列表")
    @GetMapping("/list")
    public TableDataInfo list(YardageGoodsTaskOrder yardageGoodsTaskOrder) {
        startPage();
        List<YardageGoodsTaskOrder> list = yardageGoodsTaskOrderService.selectYardageGoodsTaskOrderList(yardageGoodsTaskOrder);
        return getDataTable(list);
    }

    /**
     * 导出码货任务单列表
     */
    @ApiOperation(value = "导出码货任务单列表")
    @Log(title = "码货任务单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YardageGoodsTaskOrder yardageGoodsTaskOrder) {
        List<YardageGoodsTaskOrder> list = yardageGoodsTaskOrderService.selectYardageGoodsTaskOrderList(yardageGoodsTaskOrder);
        ExcelUtil<YardageGoodsTaskOrder> util = new ExcelUtil<YardageGoodsTaskOrder>(YardageGoodsTaskOrder.class);
        util.exportExcel(response, list, "码货任务单数据");
    }

    /**
     * 获取码货任务单详细信息
     */
    @ApiOperation(value = "获取码货任务单详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(yardageGoodsTaskOrderService.selectYardageGoodsTaskOrderById(id));
    }

    /**
     * 新增码货任务单
     */
    @ApiOperation(value = "新增码货任务单")
    @Log(title = "码货任务单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YardageGoodsTaskOrder yardageGoodsTaskOrder) {
        return toAjax(yardageGoodsTaskOrderService.insertYardageGoodsTaskOrder(yardageGoodsTaskOrder));
    }

    /**
     * 修改码货任务单
     */
    @ApiOperation(value = "修改码货任务单")
    @Log(title = "码货任务单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YardageGoodsTaskOrder yardageGoodsTaskOrder) {
        return toAjax(yardageGoodsTaskOrderService.updateYardageGoodsTaskOrder(yardageGoodsTaskOrder));
    }

    /**
     * 删除码货任务单
     */
    @ApiOperation(value = "删除码货任务单")
    @Log(title = "码货任务单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(yardageGoodsTaskOrderService.deleteYardageGoodsTaskOrderByIds(ids));
    }
    /**
     * 确认码货
     */
    @ApiOperation(value = "确认码货")
    @Log(title = "确认码货", businessType = BusinessType.UPDATE)
    @PostMapping("/confirm")
    public AjaxResult confirm(@RequestBody YardageGoodsTaskOrderConfirmVo confirmVo){
        return toAjax(yardageGoodsTaskOrderService.confirmOrComplete(confirmVo, false));
    }
    /**
     * 完成码货
     */
    @ApiOperation(value = "完成码货")
    @Log(title = "完成码货", businessType = BusinessType.UPDATE)
    @PostMapping("/complete")
    public AjaxResult complete(@RequestBody YardageGoodsTaskOrderConfirmVo confirmVo){
        return toAjax(yardageGoodsTaskOrderService.confirmOrComplete(confirmVo,true));
    }

}
